home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / ANIM / LINE_TRA.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  3.0 KB  |  115 lines

  1. package sub_arctic.anim;
  2. import java.awt.Point;
  3.  
  4. /** 
  5.  * This is a sample trajectory. It implements a line trajectory, 
  6.  * given a pacer object to do the pacing transformation.
  7.  *
  8.  * @author Ian Smith
  9.  */
  10. public class line_trajectory implements trajectory {
  11.  
  12.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  13.  
  14.   /**
  15.    * This holds the pacer we are using.
  16.    */
  17.   protected pacer _pacer;
  18.  
  19.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  20.  
  21.   /**
  22.    * Origin in x.
  23.    */
  24.   protected int _x_origin;
  25.  
  26.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  27.  
  28.   /**
  29.    * Origin in y.
  30.    */
  31.   protected int _y_origin;
  32.  
  33.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  34.  
  35.   /**
  36.    * Amount to move in x.
  37.    */
  38.   protected int _delta_x;
  39.  
  40.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  41.  
  42.   /**
  43.    * Amount to move in y.
  44.    */
  45.   protected int _delta_y;
  46.  
  47.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  48.  
  49.   /** 
  50.    * This does the work for this trajectory. It maps a point in time
  51.    * to a Point object. <p>
  52.    * 
  53.    * @param double parm the amount of time to be mapped (in the range 0.0 to 
  54.    *                    1.0)
  55.    */
  56.   public Object object_for_parm(double parm) {
  57.     double parameter=_pacer.pace(parm); // run it through the pacer
  58.     int newx, newy;
  59.  
  60.     newx=_x_origin+(int)(parameter * (double)_delta_x);
  61.     newy=_y_origin+(int)(parameter * (double)_delta_y);
  62.     return new Point(newx, newy);
  63.   }
  64.  
  65.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  66.  
  67.   /**
  68.    * This constructs this trajectory, given two points.
  69.    *
  70.    * @param int x1 starting x coordinate
  71.    * @param int y1 starting y coordinate
  72.    * @param int x2 ending x coordinate
  73.    * @param int y2 ending y coordinate
  74.    */
  75.   public line_trajectory(int x1, int y1, int x2, int y2, pacer p) {
  76.  
  77.     /* get the vars set up */
  78.     _x_origin=x1;
  79.     _delta_x=x2-x1;
  80.     _y_origin=y1;
  81.     _delta_y=y2-y1;
  82.  
  83.     /* copy the pacing function */
  84.     _pacer=p;
  85.   }
  86.  
  87.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  88.  
  89.   /**
  90.    * Return the pacing function.
  91.    * @return pacer the pacing function we are using for this trajectory
  92.    */
  93.   public pacer pacing_function() { return _pacer;};
  94.  
  95.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  96.  
  97. }
  98.  
  99. /*=========================== COPYRIGHT NOTICE ===========================
  100.  
  101. This file is part of the subArctic user interface toolkit.
  102.  
  103. Copyright (c) 1996 Scott Hudson and Ian Smith
  104. All rights reserved.
  105.  
  106. The subArctic system is freely available for most uses under the terms
  107. and conditions described in 
  108.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  109. and appearing in full in the lib/interactor.java source file.
  110.  
  111. The current release and additional information about this software can be 
  112. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  113.  
  114. ========================================================================*/
  115.